// $Id$
package de.servicezombie.cxf;

import java.lang.reflect.Type;

import javax.ws.rs.ext.ContextResolver;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import org.apache.cxf.jaxrs.provider.JSONProvider;

/**
 * CXF uses a JSONProvider for binding JSON in RESTful services
 */
public class ContextResolverAwareJSONProvider extends JSONProvider {
	
	private ContextResolver<JAXBContext> contextResolver;
	
	public void setContextResolver(ContextResolver<JAXBContext> contextResolver) {
		this.contextResolver = contextResolver;
	}

	@Override
	protected JAXBContext getJAXBContext(Class<?> type, Type genericType) throws JAXBException {
		
		JAXBContext context = CachingJaxbContextResolver.getJAXBContext(contextResolver, type);
		if (context == null) {
			context = super.getJAXBContext(type, genericType);
		}
		return context;
	}
	
	

}
